<template>
    <div>
        <table border="1">
            <tbody>
                <tr>
                    <th>房间号</th>
                    <th>
                        <input type="text" v-model="data.Num">
                    </th> 
                </tr>
                <tr>
                    <th>房间名称</th>
                    <th>
                        <input type="text" v-model="data.Name">
                    </th>
                </tr>
                <tr>
                    <th>描述</th>
                    <th>
                        <input type="text" v-model="data.Des">
                    </th>
                </tr>
                <tr>
                    <th>状态</th>
                    <th>
                            <input type="checkbox" v-model="data.State">选中启用否则禁用
                    </th>
                </tr>
                <tr>
                    <th>床位</th>
                    <th>
                        <input type="text" v-model="data.Bed">
                    </th>
                </tr>
                <tr>
                    <th>
                        <input type="button" value="添加" @click="Add">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { validateLocaleAndSetLanguage } from 'typescript';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const data=ref({
    "Id": 0,
  "Num": "",
  "Name": "",
  "Des": "",
  "State": true,
  "Bed": "",
  "Delete": true
})

const router=useRouter();

const Add=()=>{
    if(data.value.Name=="廖娜"){
        alert('姓名重复')
    }
    axios.post("https://localhost:7198/api/Home/AddHome",data.value).then(res=>{
        if(res.data>0){
            alert('添加成功')
            router.push({path:"/ShowView"})
        }
        else{
            alert('失败')
        }
    })
}



</script>

